package com.wgts.wgts.mvp.view.activity.shopkeeper;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.control.recycleview.BaseLoadMoreAdapter;
import com.wgts.wgts.netmodle.resp.UserMoneyRecordEntity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ForwardOrderAdapter extends BaseLoadMoreAdapter<ForwardOrderAdapter.ForwardOrderViewHolder> {



    private Context context;

    private List<UserMoneyRecordEntity> entities;

    private OnClickListener onClickListener;


    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public ForwardOrderAdapter(Context context, List<UserMoneyRecordEntity> entities) {
        super(context);
        this.context = context;
        this.entities = entities;
    }

    @Override
    public void onBindBodyViewHolder(@NonNull ForwardOrderViewHolder viewHolder, final int i) {
        viewHolder.tvBank.setText(entities.get(i).takeTypeName);
        viewHolder.tvYear.setText(entities.get(i).takeDate);
        viewHolder.tvTime.setText(entities.get(i).takeTime);
        viewHolder.tvMoney.setText(String.valueOf("-" + entities.get(i).money) + "元");
        viewHolder.tvBankNumber.setText(String.valueOf(entities.get(i).takeTypeCode));
        switch (entities.get(i).status){
            case "0":
                viewHolder.tvState.setText("审核中");
                viewHolder.tvState.setTextColor(ContextCompat.getColor(context, R.color.read_text));
                break;
            case "1":
                viewHolder.tvState.setText("审核通过");
                viewHolder.tvState.setTextColor(ContextCompat.getColor(context, R.color.read_text));
                break;
            case "2":
                viewHolder.tvState.setText("审核失败");
                viewHolder.tvState.setTextColor(ContextCompat.getColor(context, R.color.read_text));
                break;
        }
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onClickListener != null){
                    onClickListener.onClick(v, i);
                }
            }
        });
    }

    @NonNull
    @Override
    public ForwardOrderViewHolder onCreateBodyViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ForwardOrderViewHolder(LayoutInflater.from(context).inflate(R.layout.forward_order_item, viewGroup, false));
    }

    @Override
    public int getBodyItemCount() {
        return entities.size();
    }

    @Override
    public int getBodyItemViewType(int position) {
        return entities.size();
    }

    public class ForwardOrderViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_year)
        TextView tvYear;
        @BindView(R.id.tv_bank)
        TextView tvBank;
        @BindView(R.id.tv_money)
        TextView tvMoney;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.tv_bank_number)
        TextView tvBankNumber;
        @BindView(R.id.tv_state)
        TextView tvState;

        public View itemView;
        public ForwardOrderViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            this.itemView = itemView;
        }
    }

    public interface OnClickListener{
        void onClick(View view, int i);
    }


}
